package com.example.mybatisplus.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.example.mybatisplus.pojo.General;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

@Mapper
public interface GeneralMapper extends BaseMapper<General> {
    @Select("select * from general where name=#{name}")
    public List<General> selectByName(@Param("name") String name);
//    @Delete("delete from general where id=#{id}")
//    public int deleteById(@Param("id")Integer id);

    //注意：是无法2个同时存在updateById。原因不知道
//    @Update("update general set name=#{name},create_time=#{date} where id=#{id}")
//    public int updateById(@Param("name")String name, @Param("date")Date date,@Param("id")Integer id);


    //如果是自己写的，那么乐观锁是不会为我们写的进行version判断、set的version
    @Update("update general set name=#{et.name},create_time=#{et.createTime},version=#{et.version} where id=#{et.id} AND version=#{et.version}-1 AND logicDeleteState=false" )
    public int updateById(@Param(Constants.ENTITY)General general);

    //进行逻辑恢复，通过id来判断
    @Update("update general set logic_delete_state=#{logicDeleteState} where id=#{id}" )
    public int updateLogicDeleteStateById(@Param("logicDeleteState") Boolean logicDeleteState, @Param("id")Integer id);

    @Insert("insert into general(name,create_time,version,logic_delete_state) values(#{et.name},#{et.createTime},#{et.version},#{et.logicDeleteState})")
    public int insert(@Param("et")General general);

}
